package com.itjiange;

import java.util.Stack;

/**
 * @author ItJianGe
 * @data 2024/8/28 9:44
 */
public class MementoManager {

    private Stack<Memento> mementoStack = new Stack<>();

    /**
     * 保存到备忘录
     *
     * @param document
     */
    public void save(Document document) {
        Memento memento = new Memento(document.getContext());
        mementoStack.add(memento);
    }

    public void annul(Document document) {
        Memento pop = mementoStack.pop();
        document.setContext(pop.getContext());
    }
}
